//
// Created by 86137 on 2024/1/25.
//

#ifndef MYWORK_CAN_COMMUNICATE_TASK_H
#define MYWORK_CAN_COMMUNICATE_TASK_H


#ifdef __cplusplus
extern "C" {
#endif

#include "can.h"
#include "LK_motor_driver.h"
#include "DJI_motor_driver.h"
#include "DM_motor_driver.h"
#include "pwm_motor_driver.h"
#include "chassis_data_calculate.h"
#include "arm_math.h"
#include "math.h"
#include "drv_dr16.h"
#include "send_calculate.h"

void can_communicate_task(void *argument);
#pragma pack(1)
typedef struct {
    int16_t x:12;
    int16_t y:12;
    uint16_t z:11;
    int16_t yaw:10;
    uint8_t is_cut_on:1;
    uint8_t msg_able:1;
    uint8_t reverse_1:1;
    uint8_t reverse_2:8;
    uint8_t reverse_3:8;
} ctrl_msg_tran;
#pragma pack()


#pragma pack(1)
typedef struct {
    int16_t x:12;
    int16_t y:12;
    uint16_t z:11;
    int16_t yaw:10;
    uint8_t is_ready:1;
    uint8_t reverse_1:2;
    uint8_t reverse_2:8;
    uint8_t reverse_3:8;
} ctrl_arm_msg_receive;
#pragma pack()

#pragma pack(1)
typedef struct{
    float x;
    float y;
}ctrl_vision_msg_0_receive;
#pragma pack()

#pragma pack(1)
typedef struct{
    float z;
    uint8_t target_detected:1;
    uint32_t reverse:31;
}ctrl_vision_msg_z_receive;
#pragma pack()

const float GAIN_TX = 4.5f;
const float GAIN_RX = (1.0f / 4.5f);

typedef struct {
    float x;
    float y;
    float z;
    float yaw;
    uint8_t is_ready;
} CtrlMsg_arm;

typedef struct {
    float x;
    float y;
    float z;
    uint8_t target_detected;
}CtrlMsg_vision;

void rx_arm_callback(can_device_receive *can_receive, uint8_t *data);
void rx_vision_0_callback(can_device_receive *can_receive, uint8_t *data);
void rx_vision_z_callback(can_device_receive *can_receive, uint8_t *data);

#ifdef __cplusplus
}
#endif

#endif //MYWORK_CAN_COMMUNICATE_TASK_H
